import getPageBySlug from "@/ssr/getPageBySlug"
import PageTemplate from "@/template/pages/PageTemplate"
import Draft from "@/components/common/Draft"

export async function generateMetadata({ params }) {
  const { slug } = await params
  const res = await getPageBySlug(slug)
  return {
    title: res?.meta_title || res?.title,
    description: res?.meta_description || res?.description,
  }
}

export default async function Page({ params }) {
  const { slug } = await params;
  const res = await getPageBySlug(slug);
  if (res?.status === 1) { return <Draft /> }

  return (
    <div className="page">
      <PageTemplate template={res?.template || "default"} info={res} />
    </div>
  )
}
